package com.zhangqiang.git.cloud.producer1.controller;

import com.zhangqiang.git.cloud.domain.consumer.SysUser;
import com.zhangqiang.git.cloud.remote.model.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/producer1")
@RefreshScope // 增加RefreshScope注释 获取实时刷新最新的配置信息
public class Producer1Controller {

    @Value("${project_name}")
    private String project_name;

    @Value("${common_name}")
    private String common_name;

    @Autowired
    private RemoteUserService remoteUserService;

    @GetMapping("/project/name")
    public String findConfig(){

        return "project_name:"+project_name+" common_name:"+common_name;
    }

    @GetMapping("/user/name")
    public String findUserName(){
        SysUser sysUser = remoteUserService.findUserByName("admin");
        if(sysUser==null){
            return "用户不存在";
        }
        return sysUser.getUserName();
    }
}
